package Services

import(
	"github.com/gin-gonic/gin"
	"fmt"
	"net/http"
	"gin/Databases"
	"gin/Middlewares"
	"strconv"
)

// 添加属性数据
func AttrDataAdd(c *gin.Context) {
	if (!Middlewares.CheckLogin(c)) {
		c.JSON(http.StatusOK, gin.H{
	        "result": -1,
	        "msg":    "login fail",
	        "data": "{}",
	    })
	    return
	}

	code := c.Query("code")
	code_type,_ := strconv.Atoi(c.Query("code_type"))
	//relation_id := Common.GetRelation03Id(c.Query("attr_type"))
	relation_id,_ := strconv.Atoi(c.Query("attr_type"))
	title := c.Query("title")
	url := c.Query("url")
	site := c.Query("site")
	date := c.Query("date")

	sql := "insert into relation_data_03_temp (Fsrc_code,Fsrc_type,Frelation_id,Ftitle,Fdate,Furl,Fsite,Fstatus,Fcreate_time,Fmodify_time) values (?,?,?,?,?,?,?,0,now(),now());"
	_,err := Databases.Db.Exec(sql, code, code_type, relation_id, title, date, url, site)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
	        "result": -1,
	        "msg":    "insert fail",
	        "data": "{}",
	    })
		fmt.Println("insert failed, ", err)
		return
	}

    c.JSON(http.StatusOK, gin.H{
        "result": 0,
        "msg":    "success",
        "data": "",
    })
}

